package db;

import java.util.Date;
import java.util.List;

import org.hibernate.Session;

public class TestHibernate {
	
	public static void main(String[] args) {
		Session session = DbUtils.startSession();
//		for (int i = 0; i < 5; i++) {
//			System.out.println("will add " + i);
//			DbUtils.addUser(session, "fake" + i, "userPassword" + i);
//			System.out.println("done " + i);
//		}
		List<User> allUsers = DbUtils.getAllUsers(session);
		for(User user : allUsers) {
			System.out.println("Id: " + user.getUserId());
			System.out.println("Username: " + user.getUserName());
			System.out.println("Password: " + user.getUserPassword());
//			DbUtils.deleteUser(session, user.getUserId());
//			session.getTransaction().commit();
//			session.beginTransaction();
		}
//		
//		Album album = DbUtils.findAlbum(session, 1);
//		System.out.println(album.getAlbumName());
//		List<Album> childs = album.getChildAlbums();
//		if(childs.isEmpty()) {
//			System.out.println("\tNo childs.");
//		}else {
//			System.out.println("\tChilds: ");
//			for(Album child : childs) {
//				System.out.println("\t" + child.getAlbumName());
//			}
//		}
//		
//		List<Picture> pics = album.getPictures();
//		for(Picture p : pics) {
//			System.out.println(p.getPictureId() + ": " + p.getPictureTitle() + "." + p.getPictureFormat() + " -  user: " + p.getAlbum().getUser());
//		}
	
//		Date date = new Date();
//		for(int index = 0; index < 10; index++) {
//			String name = "pict_";
//			name = name.concat(String.valueOf(index));
//			String type = "jpg";
//			long albumId = 1;
//			if(index % 2 == 0) {
//				type = "gif";
//				albumId = 1;
//			}else if(index % 3 == 0) {
//				type = "png";
//				albumId = 1;
//			}
//			long id = DbUtils.addPicture(session, name, type, albumId, date);
//			System.out.println(id);
//		}
	
		
		 
//		DbUtils.addUser(session, "testUser55", "password");
//		if(DbUtils.isValidUser(session, "testUser55", "password")) {
//			System.out.println("Welcome!");
//		}else{
//			System.out.println("Error");
//		}
		
		
		/*
		System.out.println();
		System.out.println("16 pics:");
		List<Picture> pictures = DbUtils.get16Pictures(session, 2, 2);
		for(Picture pict : pictures) {
			System.out.println("Name: " + pict.getPictureTitle() + "." + pict.getPictureFormat());
		}
		*/
		
		//DbUtils.editComment(session, 1, "The best body!");
		
		//DbUtils.addAlbum(session, "New Girls", 3);
		
		/*
		System.out.println("Picture path test: ");
		String path = DbUtils.getPicturePath(session, 1);
		System.out.println(path);
		System.out.println("Album path test: ");
		String path1 = DbUtils.getAlbumPath(session, 101);
		System.out.println(path1);
		*/
//		Album album = DbUtils.findAlbum(session, 1);
//		List<Album> allUsers = album.getChildAlbums();
//		for(Album user : allUsers) {
//			System.out.println("Id: " + user.getAlbumId());
//			System.out.println("Name: " + user.getAlbumName());
//			
//		}
		//DbUtils.deleteAlbum(session, 1);
		//System.out.println(DbUtils.getAllPicturesNumByAlbum(session, 1));
		
		//long id = DbUtils.getALbumIdByName(session, "party", 1);
		//System.out.println(id);
		//DbUtils.deleteUser(session, 221);
		
		
		
		
		session.getTransaction().commit();
		session.close();
	}
}
